<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="layout :: common_header(~{::title})">
    <title>库存管理-商品列表</title>
</head>
<body th:replace="layout :: common_body(~{::div.layui-body})">

<div class="layui-body" style="padding:15px;top: 0px;">
    <!-- start sp-wrapper -->
    <link rel="stylesheet" href="/sb/stock.css"/>
    <div class="sp-wrapper">
        <h2 class="sp-title"><span>商品规格变更</span></h2>
        <div class="sp-tool">
            <form action="/goods/list" method="post">
                <div class="layui-form-item">
                    <label class="layui-form-label">变更前规格</label>
                    <div class="layui-input-block">
                        <select id="oldSpec" lay-filter="aihao" style="width: 500px">
                            <option value="">请选择变更前的规格</option>
                            <option th:each="item:${list}" th:value="${item.getId()}" th:text="${'规格：'+item.getSpecNumber()+'商品：' +item.getName()+'_'+item.getSpecName()}" ></option>
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">变更后规格</label>
                    <div class="layui-input-block">
                        <select id="newSpec" lay-filter="aihao" style="width: 500px">
                            <option value="">请选择变更后的规格</option>
                            <option th:each="item:${list}" th:value="${item.getId()}" th:text="${'规格：'+item.getSpecNumber()+'商品：' +item.getName()+'_'+item.getSpecName()}" ></option>
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button type="button" id="upd_good_spec" class="layui-btn" lay-submit lay-filter="demo1">立即提交</button>
                    </div>
                </div>
            </form>

        </div>
    </div>
    <script type="text/javascript" src="/sb/Tips.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $('#upd_good_spec').click(function () {
                var oldSpec = $("#oldSpec  option:selected").val();
                if (oldSpec == '') {
                    Tips.alert("请选择变更前规格");
                    return false;
                }
                var newSpec = $("#newSpec  option:selected").val();
                if (newSpec == '') {
                    Tips.alert("请选择变更后规格");
                    return false;
                }
                if(oldSpec==newSpec){
                    Tips.alert("前后规格选择一致");
                    return false;
                }
                data = {
                    oldSpecId: oldSpec,
                    newSpecId: newSpec
                }
                $.ajax({
                    url: '/ajax_erp_good_spec/upd_erp_good_spec_by_id',
                    type: "POST",
                    dataType: 'json',
                    contentType: 'application/json',
                    data: JSON.stringify(data),
                    success: function (res) {
                        if (res.code == 0) {
                            Tips.alert('变更成功', function () {
                                location.reload(true);
                            });
                        } else {
                            alert(res.msg);
                        }
                        return false;
                    }
                });
                return false;
            });
        });
    </script>
</div>
</body>
</html>
